package com.example.nacostest.controller;

import com.example.nacostest.feignapi.paycenter.PayCenterFeignApi;
import com.example.nacostest.feignapi.productcenter.ProductCenterFeignApi;
import com.example.nacostest.pojo.OrderVo;
import com.example.nacostest.pojo.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
@RequestMapping
@RestController
public class FeignController {

    @Autowired
    private ProductCenterFeignApi productCenterFeignApi;
    @Autowired
    private PayCenterFeignApi payCenterFeignApi;

    @RequestMapping("/selectOrderInfoById/{orderNo}")
    public Object selectOrderInfoById(@PathVariable("orderNo") String orderNo) {


        ProductInfo productInfo = productCenterFeignApi.selectProductInfoById(orderNo);

        if (productInfo == null) {
            return "没有对应的商品";
        }

        return productInfo;
    }

    @RequestMapping("/testFeignInctercept")
    public String testFeignInctercept(@RequestBody Map<String, Object> params, @RequestHeader("token") String token) {
        System.out.println(params.toString());
        return productCenterFeignApi.getToken4Header();// 这里会调用 TulingRequestInterceptor 将token放如feign的拦截器中
    }

    @RequestMapping("/testPay")
    public String testPay() {
        return payCenterFeignApi.test();
    }

}
